package com.cjl.algorithm.tree;

import java.io.File;

public class DirHelper {

    private static final String path = "/usr";

    public static int tableCount = 0;

    public static void main(String[] args) {
        tableCount = 0;

        listDirs(path,3);
    }


    public static void listDirs(String path,int depth){
        if (path == null || path.length() == 0){
            throw new NullPointerException("path is null or empty");
        }

        if (depth <= 0){
            return;
        }

        int pathLength = path.length();
        File file = new File(path);
        if (file.isDirectory()){
            File[] children = file.listFiles();
            if (children != null){
                for (File child : children) {
                    for (int i = 0; i < pathLength; i++) {
                        System.out.print(" ");
                    }
                    System.out.println(child.getName()+(child.isFile()? ".file":""));
                    listDirs(child.getAbsolutePath(),depth-1);
                }
            }
        }else {
            for (int i = 0; i < pathLength; i++) {
                System.out.print(" ");
            }
            System.out.println(file.getName()+(".file"));
        }


    }
}
